home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.programming / comp.sys.amiga.programmer_24312_000012.msg < prev    next >
Encoding:
Internet Message Format  |  1994-11-27  |  3.2 KB

  1. Path: etek.chalmers.se!chalmers.se!sunic!uunet!stanford.edu!rutgers!cbmvax!peter
  2. From: peter@cbmvax.commodore.com (Peter Cherna)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: RKM description of WaitPort()
  5. Message-ID: <38305@cbmvax.commodore.com>
  6. Date: 5 Jan 93 15:50:15 GMT
  7. References: <1993Jan1.221013.26070@urbana.mcd.mot.com> <1ib7peINNele@uwm.edu>
  8. Reply-To: peter@cbmvax.commodore.com (Peter Cherna)
  9. Organization: Commodore-Amiga, Inc.  West Chester, PA.
  10. Lines: 77
  11.  
  12. In article <1ib7peINNele@uwm.edu> bloc1469@ee.ee.uwm.edu (Gregory R Block) writes:
  13. >In article <1993Jan1.221013.26070@urbana.mcd.mot.com> qbarnes@urbana.mcd.mot.com (Quentin Barnes) writes:
  14. >>It seems to me to OS is waking up the task before it has attached the
  15. >>message to the specified port
  16.  
  17. >No, it's just possible to send a signal to a port without sending a
  18. >message.
  19.  
  20. In general (99.999%?) one doesn't signal a port without sending a
  21. message.  That's not the issue at all.  I'll show two quite possible
  22. scenarios for the order of message arrival and application processing
  23. of messages, and you'll see quite easily how the signal might be
  24. set even though there are no waiting messages.
  25.  
  26. Because messages queue but signals don't, there can be multiple
  27. messages for one signal (in this case two).  Thus, an application
  28. must remove ALL messages from the message port when it wakes up,
  29. which is why you often see:
  30.  
  31.     while ( msg = GetMsg( port ) )
  32.     {
  33.         ...
  34.     }
  35.  
  36. Scenario A:
  37.  
  38.  - Message 1 arrives and is queued, and the signal is set.
  39.  
  40.  - Message 2 arrives and is queued, and signal is set (which has
  41.    no effect, since the signal was already set).
  42.  
  43.  - Your application wakes up, clearing the signal.
  44.  
  45.  - The application GetMsg()s Message 1 and processes it.
  46.  
  47.  - The application GetMsg()s Message 2 and processes it.
  48.  
  49.  - The application finds no further messages, so Wait()s for the next
  50.    signal.
  51.  
  52. OK, now consider a slightly different order of arrival:
  53.  
  54.  
  55. Scenario B:
  56.  
  57.  - Message 1 arrives and is queued, and the signal is set.
  58.  
  59.  - Your application wakes up, clearing the signal.
  60.  
  61.  - The application  GetMsg()s Message 1 and starts to process it.
  62.  
  63.  - Message 2 arrives and is queued, and the signal is set.
  64.  
  65.  - Your application finishes with Message 1, and like all well-written
  66.    applications, you loop back to see if there are any more messages
  67.    queued, and you find Message 2, so you GetMsg() that and process
  68.    it.  NOTE that you didn't WaitPort() a second time, so the signal
  69.    is not cleared.
  70.  
  71.  - You're done with Message 2, and find no further messages on your
  72.    port, so you WaitPort().
  73.  
  74.  - You wake up immediately because there was a left-over signal, as
  75.    described above.  So you check for messages, and there are none.
  76.  
  77. To summarize:  because messages queue and signals do not, you have to
  78. exhaust the message port for every signal received.  Because you do
  79. that, you might end up with a set signal whose messages you've already
  80. processed.
  81.  
  82.  
  83.      Peter
  84. --
  85. Peter Cherna, User Interface Development Group, Commodore-Amiga, Inc.
  86. {uunet|rutgers}!cbmvax!peter    peter@cbmvax.commodore.com
  87. My opinions do not necessarily represent the opinions of my employer.
  88. "Opinions enlarged to show detail"